home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Run Magazine ReRun 1985 Summer
/
rerun-1985-summer-side-b.d64
/
number puzzle
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
4KB
|
136 lines
0 rem fifteen puzzle v 4.4 for c-64,written for trs-80 by w.l.colsher
10 rem kb/microcomp.,v.5,p.114,feb.1981.modified and converted for c-64 by
20 rem z.szepesi 2611 saybrook drive,pittsburgh,pa 15235
30 poke53281,13:poke53280,2:print"[147][144] fifteen puzzle."
40 print" [184][184][184][184][184][184][184][184][184][184][184][184][184][184][184]"
50 print" **do you need instructions?"
60 print" press 'y', or any other key for no."
70 geta$:ifa$=""then70
80 ifa$="y"thengosub1310
90 rem ***initialisation************************
100 dim a(20):m=0:s=54272:print"[147]"
110 a$=" [213][195][195][195][195][178][195][195][195][195][178][195][195][195][195][178][195][195][195][195][201]":rem sh=shift;cm=commodore key in following
120 rem space;sh u;4 sh c;cm r;4 sh c;cm r;4 sh c;cm r;4 sh c;sh i
130 b$=" [171][192][192][192][192][219][192][192][192][192][219][192][192][192][192][219][192][192][192][192][179]"
140 rem space;cm q;4 sh c;sh +;4 sh c;sh +;4 sh c;sh +;4 sh c;cm w
150 c$=" [194] [160][160][160][221][160][160][160][160][221][160][160][160][160][221][160][160][160][160][194]"
160 rem space;sh b;4 space;sh b;4 space;sh b;4 space;sh b;4 space;sh b
170 d$=" [202][195][195][195][195][177][195][195][195][195][177][195][195][195][195][177][195][195][195][195][203]"
180 rem space;sh j;4 sh c;cm e;4 sh c;cm e;4 sh c;cm e;4 sh c;sh k
190 printa$:fori=1to3
200 printc$:printc$:printb$:nexti
210 printc$:printc$:printd$:ifq=1then return
220 print" **wait please"
230 forx=1to16:a(x)=0:next:rem **creating a set of random numbers**
240 fori=1to16
250 x=int(16*rnd(rnd(0)))+1:ifa(x)then250
260 a(x)=i:next
270 gosub510:ti$="000000":iff=0then230
280 print:gosub610:print:print" ":rem 17 spaces
290 print"[145] *your move";:x$="":x1$="":rem **play starts*****
300 getx$:ifx$=""then300
310 ifx$="_"thenx=1:goto350
320 ifx$<>"1"goto340
330 getx1$:ifx1$=""goto330
340 x$=x$+x1$:x=val(x$)
350 printx:gosub410:gosub710:iff then370
360 print" *illegal move,re-enter":goto280
370 a(x+f)=a(x):a(x)=16:goto910
380 m=m+1:goto280
400 rem ***convert number to location in array***
410 fori=1to16:ifa(i)=xthen430
420 next
430 x=i:return
500 rem ***verify if solution is possible********
510 f=0:su=0:fori=1to15:forj=i+1to16
520 ifa(i)>a(j)thensu=su+1
530 nextj:nexti:restore
540 fori=1to8:readx:ifa(x)=16thensu=su+1
550 nexti
560 a=int(su/2):ifa*2=suthenf=1
570 return
580 data2,4,5,7,10,12,13,15
600 rem ***display game board********************
610 print"":print:fori=1to4:print
620 printspc(1):forj=1to4:n=a((i-1)*4+j):printspc(1);:n$=str$(n)
630 ifn<10thenprint" ";
640 ifn=16then n$=" "
650 printn$;spc(1);
660 nextj:print:print
670 nexti
680 print:return
700 rem ***check for legal move******************
710 f=0:ifx>16then return
720 if(x=4orx=8orx=12)anda(x+1)=16thenreturn
730 if(x=5orx=9orx=13)anda(x-1)=16thenreturn
740 ifx+1>16then760
750 ifa(x+1)=16thenf=1
760 ifx-1<=0then780
770 ifa(x-1)=16thenf=-1
780 ifx+4>16then800
790 ifa(x+4)=16thenf=4
800 ifx-4<0then820
810 ifa(x-4)=16thenf=-4
820 iff thenprint" ":rem 26 spaces
830 return
900 rem ***check for a win***********************
910 fori=1to16
920 ifa(i)<>ithen380
930 next
940 gosub610:t$=ti$
950 gosub1110:print"[147] *congratulations!!!"
960 print" you did it in only"m"moves!!"
970 print" *and you needed "val(mid$(t$,1,2))"hour,";
980 print val(mid$(t$,3,2))"minutes"
990 print" and"val(mid$(t$,5,2))"seconds."
1000 print" **press 'y' to play again or any other key to end."
1010 geta$:ifa$=""then1010
1020 ifa$="y"thenclr:goto100
1030 end
1100 rem ***sound subroutines*********************
1110 forl=stos+24:pokel,0:next:pokes+24,15
1120 pokes+5,0:pokes+12,0:pokes+19,0:pokes+6,240:pokes+13,240:pokes+20,240
1130 restore
1140 fori=1to8:readz:next
1150 readh1,h2,h3:ifh1=-1thenforl=stos+24:pokel,0:next:return
1160 readl1,l2,l3,d:pokes+1,h1:pokes+8,h2:pokes+15,h3
1170 pokes,l1:pokes+7,l2:pokes+14,l3:pokes+4,17:pokes+11,17:pokes+18,17
1180 fort=1tod:next:pokes+4,16:pokes+11,16:pokes+18,16:fort=1to50:next:goto1150
1190 data25,12,6,30,143,71,100
1200 data25,12,6,30,143,71,100
1210 data25,12,6,30,143,71,100
1220 data19,9,4,239,247,251,400,0,0,0,0,0,0,100
1230 data22,11,5,96,48,152,100
1240 data22,11,5,96,48,152,100
1250 data22,11,5,96,48,152,100
1260 data18,9,4,209,104,180,800,-1,1,1
1300 rem ***instructions**************************
1310 print"[147] fifteen puzzle"
1320 print" [183][183][183][183][183][183][183][183][183][183][183][183][183][183]"
1330 print" *the object of the fifteen puzzle is"
1340 print" to move the numbers around, so that"
1350 print" they are in order from 1 to 15."
1360 print" a move is made by typing in the number"
1370 print" you wish to move. however, if you"
1380 print" want to move the number '1', press"
1390 print" instead the left arrow ('_')."
1400 print" *the number to be moved must be"
1410 print" adjacent to the empty square."
1420 print" the typed number then moves into the"
1430 print" empty square."
1440 print" *do not press return after typing the"
1450 print" number."
1460 print" *you win, when the board looks like the"
1470 print"[145] figure which follows:"
1480 print" **press any key to continue"
1490 geta$:ifa$=""then1490
1500 q=1:gosub100
1510 fori=1to16:a(i)=i:nexti
1520 gosub610
1530 print" **press any key to start"
1540 geta$:ifa$=""then1540
1550 q=0:clr:goto100
1560 print" **press anz key to continue"
1570 geta$:ifa$=""then1570
1580 print"[147]":return